package com.pig4cloud.pig.djjk.service.immi;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.pig4cloud.pig.djjk.config.FaceApiConfig;
import com.pig4cloud.pig.djjk.domain.po.TraceResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import static com.pig4cloud.pig.djjk.utils.HttpUtil.postRequest;
import java.util.List;
import java.util.logging.Logger;

/**
 * @className: CutService
 * @description: TODO 类描述
 * @author: liumingkun
 * @date: 2025/6/24
 **/
@Service
public class CutService {


	Logger log = Logger.getLogger(FaceApiService.class.getName());

	@Autowired
	FaceApiConfig faceApiConfig;

	//获取人员轨迹
	public String getCutPic(String base64Img, List<Integer> points) {

		try {

			JSONObject json = new JSONObject();

			json.put("image", base64Img);
			json.put("points", points);

			// Create HTTP POST request
			log.info("请求地址:"+faceApiConfig.getCutUrl());
			String responseString = postRequest(faceApiConfig.getCutUrl(), json.toString());
			if (StringUtils.isNotEmpty(responseString)) {
				TraceResponse traceResponse = JSON.parseObject(
						responseString,
						new TypeReference<TraceResponse>() {
						}
				);
				if (StringUtils.isNotEmpty(traceResponse.getImage())) {
					return traceResponse.getImage();
				} else {
					log.info("获取人员轨迹失败");
					return null;
				}
			}
			return null;

		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
